package com.baoyang.tool.utils;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtils {
    public static String getCurrentUserId() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication != null && authentication.getPrincipal() != null) {
            // 假设 principal 里存的就是用户ID
            // 如果是UserDetails，可以强转后取ID
            return authentication.getPrincipal().toString();
        }
        return null;
    }
}
